/**
 * Created by YeziAny on 2017/11/11.
 */

$("#uploadFile").click(function () {
    upload_flag_ZIP(urlLink);
})
//上传文件
function upload_flag_ZIP(urlLink) {
    var fileValue=$("#uploadfile-1").val();
    var fileName=getFileName(fileValue);
    var selectFileKind=$("#selectFileKind").val();

    if (selectFileKind!=0 && !judgeNameIsRight(fileName,selectFileKind)){
        alert("上传文件命名不规范，请重新命名")
        return false;
    }else{
        var formData=new FormData();
        formData.append("nation_file",$("#uploadfile-1")[0].files[0]);
        formData.append("selectFileKind",selectFileKind);
        $.ajax({
            url:urlLink,
            type:"post",
            data: formData,
            async:false,
            xhrFields: {
                withCredentials: true
            },
            cache: false,
            contentType: false,
            processData: false,
            // dataType : "json",
            scriptCharset: 'utf-8',
            // contentType: "application/x-www-form-urlencoded; charset=utf-8",
            success:function (data) {

                alert(data);

            },
            error:function (data) {
                alert("服务器处理失败！");
            }
        })//ajax
    }
}

//    获取文件名
function getFileName(fileValue) {
    var strFileName=fileValue.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi,"$1");  //正则表达式获取文件名，不带后缀
    var FileExt=fileValue.replace(/.+\./,"");   //正则表达式获取后缀
    return strFileName;
}
//    判断命名规范
function judgeNameIsRight(fileName,index) {
    if (fileName != rightName[index-1] || fileName==null || fileName==""){
        return false;
    }else{
        return true;
    }
}